<script>
import OrderService from "@/api/order/OrderService.js";
import PPMForm from "@/crm3.0part7-ppm/core/ppmForm.vue";
export default {
  //需求单确认
  name: "demandConfirm10461091",
  mixins: [PPMForm],
  data() {
    return {};
  },

  created() {
    this.init();
  },
  methods: {
    /**
     * 初始化值
     */
    init() {
      this.formData["10461612-100012377"].value = this.user.staffName;
      this.formData["10461612-100012440"].value = this.$util.dateFormat(
        new Date(),
        "yyyy-MM-dd"
      );

      var custOrder = JSON.parse(localStorage.getItem("custOrder_select"));
      var cacheInfo = JSON.parse(localStorage.getItem("cacheInfo"));
      let temp = {
        custId: custOrder.custId,
        orderSource: "ORDER",
        custSoNumber: custOrder.custSoNumber,
        orderItemIds: cacheInfo.orderItemIds,
        taskId: cacheInfo.taskId,
      };
      this.setPageOfferDetail(temp);
    },

    /**
     * 字段回显值查询
     */
    async setPageOfferDetail(temp) {
      let res = await OrderService.qryPageOfferDetail(temp);
      console.log("res:", res);
      if (res.resultCode == "0") {
        console.log("res:", res);
        var ordProdInstAttrs = res.ORDER_DETAIL[0].ORD_PROD_INST_ATTR;
        var ordProdInsts = res.ORDER_DETAIL[0].ORD_PROD_INST;

        var ordProdInst2 = ordProdInstAttrs.filter((item) => {
          return item.attrId == "142002621" && item.roleCd == "0";
        });

        var newValue = ordProdInst2[0].attrValue;

        var ordProdInst = ordProdInsts.filter((item) => {
          return item.roleCd == 0;
        });

        var oldValue = ordProdInst[0].handleOrgId;

        // this.formData["10461612-142002621"].value = newValue;
        // this.formData["10461612-100013695"].value = oldValue;

        var params = {
          interFaceType: "ORDER",
          sqlId: "2021072802",
          paramStr: "org_Id:" + newValue,
        };

        var result = await OrderService.executeSql(params);
        console.log("result7777777:", result);
        let newOrgName = result.meta.resList.executeSqlResps[0].org_name;

        this.formData["10461612-142002621"].value = newOrgName;

        var params = {
          interFaceType: "ORDER",
          sqlId: "2021072802",
          paramStr: "org_Id:" + oldValue,
        };

        var result = await OrderService.executeSql(params);
        let originalOrgName = result.meta.resList.executeSqlResps[0].org_name;

        this.formData["10461612-100013695"].value = originalOrgName;
      }
    },
  },
};
</script>

